package me.zhengjie.modules.system.repository;


import me.zhengjie.modules.system.domain.UserInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserInfoRepository extends JpaRepository<UserInfo, Long>, JpaSpecificationExecutor<UserInfo> {

     // 条件查询 客户 或者 客户类型
     @Query(value = "SELECT * FROM user_info where if(?1 !='', user_name=?1,1=1 ) and if (?2!='',user_type=?2,1=1)",nativeQuery = true)
     List<UserInfo> fandByUserConditionList(String userName, String userType);

     // 条件查询 客户 或者 客户类型
     @Query(value = "SELECT * FROM user_info where user_id=?1",nativeQuery = true)
     UserInfo fandByUserCondition(Integer userId);

     @Transactional
     @Modifying
     @Query(value = "update user_info set user_status = ?2 where user_id =?1",nativeQuery = true)
     void updateStatus(Integer userId,String userStatus);

     @Transactional
     @Modifying
     @Query(value = "update user_info set contract_status = ?2 where user_id =?1",nativeQuery = true)
     void updateAuditStatus(String userInfoId,String contractStatus);
}
